package com.hotel.web.controller.hotel;

import com.hotel.common.annotation.Log;
import com.hotel.common.core.controller.BaseController;
import com.hotel.common.core.domain.AjaxResult;
import com.hotel.common.core.domain.entity.SysDept;
import com.hotel.common.core.page.TableDataInfo;
import com.hotel.common.enums.BusinessType;
import com.hotel.common.utils.ShiroUtils;
import com.hotel.system.domain.hotel.Expenses;
import com.hotel.system.domain.hotel.Property;
import com.hotel.system.service.ExpensesService;
import com.hotel.system.service.ISysDeptService;
import com.hotel.system.service.PropertyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 岗位信息操作处理
 * 
 * @author hotel
 */
@Controller
@RequestMapping("/hotel/property")
public class PropertyController extends BaseController
{
    private String prefix = "hotel/property";

    @Autowired
    private PropertyService propertyService;
    @Autowired
    private ISysDeptService deptService;

    @RequiresPermissions("system:kcgl:view")
    @GetMapping()
    public String operlog()
    {

        return prefix + "/post";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Property property)
    {
//        SysDept dept = new SysDept();
//        dept.setDeptId(ShiroUtils.getSysUser().getDeptId());
//        List<SysDept> deptList = deptService.selectDeptList(dept);
//        System.out.println(deptList);

        startPage();
        List<Property> list = propertyService.selectPropertyList(property);
        return getDataTable(list);
    }

    @RequiresPermissions("hotel:expenses:addExpenses")
    @GetMapping("/addProperty")
    public String addProperty()
    {
        return prefix + "/add";
    }

    @RequiresPermissions("hotel:expenses:addSave")
    @PostMapping("/addSave")
    @ResponseBody
    public AjaxResult addSave(@Validated Property property)
    {

        return toAjax( propertyService.insertProperty(property));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("post", propertyService.selectPropertyId(id));
        return prefix + "/edit";
    }

    /**
     * 出库入库调整
     */
    @PostMapping("/editProperty")
    @ResponseBody
    public AjaxResult editProperty(@Validated Property property)
    {
        return toAjax(propertyService.updateProperty(property));
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(propertyService.updatePropertyStatus(ids));
    }






}
